package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Blight;
import com.ayou.eggguard.farm.service.BlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/blight")
public class BlightController {
    @Autowired
    private BlightService blightService;

    @GetMapping("/getBlights")
    public Result<PageBean<Blight>> getBlights(int pageNum,
                                               int pageSize,
                                               @RequestParam(required = false) String blightName){
        PageBean<Blight> pb=blightService.getBlights(pageNum,pageSize,blightName);
        return Result.success(pb);
    }

    @PostMapping("/add")
    public Result addBlight(@RequestBody Blight blight){
        blightService.add(blight);
        return Result.success();
    }

    @PostMapping("/update")
    public Result updateBlight(@RequestBody Blight blight){
        blightService.update(blight);
        return Result.success();
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        blightService.delete(id);
        return Result.success();
    }

    @GetMapping("/getBlightName")
    public Result<List<String>> getBlightName(){
        List<String> list=blightService.getBlightName();
        return Result.success(list);
    }
}
